package net.midnighttd.game.resource;

import net.midnighttd.engine.ResourceManager;

import javax.swing.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * Author: Adam Scarr
 * Date: 22/04/2009
 * Time: 1:58:37 PM
 */
public class AppletResourceManager extends ResourceManager {
    private JApplet applet;

    public AppletResourceManager(JApplet applet) {
        this.applet = applet;
    }

    public InputStream getResource(String filename) {
        try {
            URL base = applet.getCodeBase();
            URL file = new URL(base.toString() + filename);
            return file.openStream();
        } catch (IOException e) {
            throw new Error("File not found" + filename);
        }
    }
   
}
